<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //判断是否是对象
        var isObject = function (obj) {
            var type = typeof obj;
            return type === 'function' || (type === 'object' && !!obj);
        }

        // 定义深拷贝对象
        var deepClone = function (obj) {
            // 如果不是对象（基本值类型）：返回自己
            if (!isObject(obj)) {
                return obj;
            }
            //如果传入的是数组 则实例化一下 返回一个空数组的实例，对象一样
            var result = new obj.constructor();
            for (var i in obj) {
                // 循环这个对象的所有属性（key）
                if (obj.hasOwnProperty(i)) {
                    result[i] = deepClone(obj[i]);
                }
            }
            return result;
        }
        // 打印拷贝效果
        // console.log(deepClone([123, { a: 1, b: { c: 2 } }, 456]))


        function Student() {
            this.name = "Hydra";
            this.age = 35;
        }

        Student.prototype.sex = "男";

        let stu = new Student();
        console.log(Object.keys(stu)); // name,age

        // name,age,sex
        for (var i in stu) {
            console.log(i);
        }

    </script>
</body>

</html>